package com.ems.controller;

import com.ems.config.LogPointer;
import com.ems.service.IOrderService;
import com.ems.vo.BaseResult;
import com.ems.vo.OrderVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 工单 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2023-11-04
 */
@RestController
@RequestMapping ( "/order" )
@CrossOrigin ( value = "*", maxAge = 3600 )
public class OrderController {

    @Resource
    private IOrderService iOrderService;

    @RequestMapping ( "queryList" )
    @LogPointer ( "工单列表" )
    public BaseResult queryList ( @RequestBody OrderVo orderVo ) {
        List<OrderVo> orderVos = iOrderService.queryList ( orderVo );
        return BaseResult.success ( orderVos, iOrderService.queryCount ( orderVo ) );
    }

    @RequestMapping ( "saveSingle" )
    @LogPointer ( "新增工单" )
    public BaseResult saveSingle ( @RequestBody OrderVo orderVo ) {
        orderVo.setOrderSource ( 1 ); // 手动创建的工单
        orderVo = iOrderService.saveSingle ( orderVo );
        return BaseResult.success ( orderVo );
    }

    @RequestMapping ( "querySingle" )
    @LogPointer ( "查询工单" )
    public BaseResult querySingle ( @RequestBody OrderVo orderVo ) {
        orderVo = iOrderService.querySingle ( orderVo );
        return BaseResult.success ( orderVo );
    }
}
